package org.esjsoftware.v2m.rim.util.contact;

/*
 * EchoChoseNumScreen.java
 *
 * <your company here>, 2003-2005
 * Confidential and proprietary.
 */

import java.util.Vector;

import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;

import org.esjsoftware.v2m.rim.ui.BasePopupScreen;
import org.esjsoftware.v2m.rim.ui.ErnestButtonField;
import org.esjsoftware.v2m.rim.ui.UIManager;

/**
 * 
 */
public class ChoosePhoneNumberScreen extends BasePopupScreen {

	private HorizontalFieldManager[] _buttonManager;
	private HorizontalFieldManager _labelManager;
	private VerticalFieldManager buttonScollManager = new VerticalFieldManager(
			Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR
					| VerticalFieldManager.FIELD_HCENTER);
	private ErnestButtonField[] _button;
	
	private String phoneNumber = "";

	public ChoosePhoneNumberScreen(Vector phoneNumbers, final String displayName) {
		super.title.setText(displayName);
		_labelManager = new HorizontalFieldManager(
				HorizontalFieldManager.FIELD_HCENTER);
//		_labelManager.add(new LabelField("Hello popup"));
		try {
			_labelManager.setFont(FontFamily.forName("BBAlpha Sans").getFont(
					Font.BOLD, 20));
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		_labelManager.setPadding(0, 0, 5, 0);
		add(_labelManager);
		_buttonManager = new HorizontalFieldManager[phoneNumbers.size()];
		_button = new ErnestButtonField[phoneNumbers.size()];
		for (int i = 0; i < _buttonManager.length; i++) {
			_buttonManager[i] = new HorizontalFieldManager(
					HorizontalFieldManager.FIELD_HCENTER);
			try {
				_buttonManager[i].setFont(FontFamily.forName("BBAlpha Sans")
						.getFont(Font.BOLD, 20));
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			_buttonManager[i].setMargin(0, 0, 2, 0);
			try {
				_button[i] = new ErnestButtonField((String) phoneNumbers.elementAt(i), Integer.parseInt("FF790F", 16), FontFamily.forName("BBAlpha Sans").getFont(Font.BOLD, 20)) {
					 protected boolean navigationClick(int status, int time) {
						 String phoneNumber = this.getLabel();
						 setPhoneNumber(phoneNumber);
						 return false;
					 }
				};
			} catch (NumberFormatException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			_buttonManager[i].add(_button[i]);
			buttonScollManager.add(_buttonManager[i]);
		}
		add(buttonScollManager);
	}
	
	public String getPhoneNumber() {
		return phoneNumber;
	}
	
	public void setPhoneNumber(String phoneNumber){
		this.phoneNumber = phoneNumber;
	}
	
	public void show() {
		UIManager.showScreen(this);
	}

}
